package com.wangshang.team.commodity.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wangshang.team.commodity.po.TeamCommodityInfo;
import com.wangshang.team.commodity.po.TeamCommodityInfoId;

/**
 * A data access object (DAO) providing persistence and search support for
 * TeamCommodityInfo entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.wangshang.team.commodity.po.TeamCommodityInfo
 * @author MyEclipse Persistence Tools
 */

public class TeamCommodityInfoDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory
			.getLog(TeamCommodityInfoDAO.class);
	// property constants
	public static final String COMMODITY_NAME = "commodityName";
	public static final String SHOP_NAME = "shopName";
	public static final String SHOP_ADDR = "shopAddr";
	public static final String SHOP_CONNECT = "shopConnect";
	public static final String SAY_SOMETHING = "saySomething";
	public static final String PICTURE_PATH = "picturePath";
	public static final String PLACE_ID = "placeId";
	public static final String PLACE_MASK = "placeMask";
	public static final String TEAM_SHOP_COMMODITY_NORM1 = "teamShopCommodityNorm1";
	public static final String TEAM_SHOP_COMMODITY_NORM2 = "teamShopCommodityNorm2";
	public static final String TEAM_SHOP_COMMODITY_NORM3 = "teamShopCommodityNorm3";
	public static final String TEAM_SHOP_COMMODITY_NORM4 = "teamShopCommodityNorm4";
	public static final String TEAM_SHOP_COMMODITY_NORM5 = "teamShopCommodityNorm5";
	public static final String COMMODITY_SOURCE_PLACE_ID = "commoditySourcePlaceId";

	protected void initDao() {
		// do nothing
	}

	public void save(TeamCommodityInfo transientInstance) {
		log.debug("saving TeamCommodityInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TeamCommodityInfo persistentInstance) {
		log.debug("deleting TeamCommodityInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TeamCommodityInfo findById(
			com.wangshang.team.commodity.po.TeamCommodityInfoId id) {
		log.debug("getting TeamCommodityInfo instance with id: " + id);
		try {
			TeamCommodityInfo instance = (TeamCommodityInfo) getHibernateTemplate()
					.get("com.wangshang.team.commodity.TeamCommodityInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(TeamCommodityInfo instance) {
		log.debug("finding TeamCommodityInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TeamCommodityInfo instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TeamCommodityInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCommodityName(Object commodityName) {
		return findByProperty(COMMODITY_NAME, commodityName);
	}

	public List findByShopName(Object shopName) {
		return findByProperty(SHOP_NAME, shopName);
	}

	public List findByShopAddr(Object shopAddr) {
		return findByProperty(SHOP_ADDR, shopAddr);
	}

	public List findByShopConnect(Object shopConnect) {
		return findByProperty(SHOP_CONNECT, shopConnect);
	}

	public List findBySaySomething(Object saySomething) {
		return findByProperty(SAY_SOMETHING, saySomething);
	}

	public List findByPicturePath(Object picturePath) {
		return findByProperty(PICTURE_PATH, picturePath);
	}

	public List findByPlaceId(Object placeId) {
		return findByProperty(PLACE_ID, placeId);
	}

	public List findByPlaceMask(Object placeMask) {
		return findByProperty(PLACE_MASK, placeMask);
	}

	public List findByTeamShopCommodityNorm1(Object teamShopCommodityNorm1) {
		return findByProperty(TEAM_SHOP_COMMODITY_NORM1, teamShopCommodityNorm1);
	}

	public List findByTeamShopCommodityNorm2(Object teamShopCommodityNorm2) {
		return findByProperty(TEAM_SHOP_COMMODITY_NORM2, teamShopCommodityNorm2);
	}

	public List findByTeamShopCommodityNorm3(Object teamShopCommodityNorm3) {
		return findByProperty(TEAM_SHOP_COMMODITY_NORM3, teamShopCommodityNorm3);
	}

	public List findByTeamShopCommodityNorm4(Object teamShopCommodityNorm4) {
		return findByProperty(TEAM_SHOP_COMMODITY_NORM4, teamShopCommodityNorm4);
	}

	public List findByTeamShopCommodityNorm5(Object teamShopCommodityNorm5) {
		return findByProperty(TEAM_SHOP_COMMODITY_NORM5, teamShopCommodityNorm5);
	}

	public List findByCommoditySourcePlaceId(Object commoditySourcePlaceId) {
		return findByProperty(COMMODITY_SOURCE_PLACE_ID, commoditySourcePlaceId);
	}

	public List findAll() {
		log.debug("finding all TeamCommodityInfo instances");
		try {
			String queryString = "from TeamCommodityInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TeamCommodityInfo merge(TeamCommodityInfo detachedInstance) {
		log.debug("merging TeamCommodityInfo instance");
		try {
			TeamCommodityInfo result = (TeamCommodityInfo) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TeamCommodityInfo instance) {
		log.debug("attaching dirty TeamCommodityInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TeamCommodityInfo instance) {
		log.debug("attaching clean TeamCommodityInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TeamCommodityInfoDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TeamCommodityInfoDAO) ctx.getBean("TeamCommodityInfoDAO");
	}
}